package com.vhall.component.service.filter.impl;


import com.vhall.component.entity.filter.FilterWordsEntity;
import com.vhall.component.entity.filter.vo.*;
import com.vhall.component.entity.page.vo.PageVO;
import com.vhall.component.plugin.common.support.Token;
import com.vhall.component.plugin.common.support.TokenThreadLocal;
import com.vhall.component.service.filter.FilterWordsAdmService;
import com.vhall.component.service.filter.FilterWordsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author longzhen.gong
 * @date 2021/7/2 16:26
 */
@Service
public class FilterWordsAdmServiceImpl implements FilterWordsAdmService {

    @Autowired
    private FilterWordsService filterWordsService;

    @Override
    public PageVO<FilterWordsListRspVO> list(FilterWordsListReqVO reqVO, Integer accountId) {
        return filterWordsService.list(reqVO, accountId);
    }

    @Override
    public FilterWordsCreateRspVO create(FilterWordsCreateReqVO req, Integer accountId, Integer userId) {
        String keyword = StringUtils.trim(req.getKeyword());
        FilterWordsEntity filterWordsEntity = filterWordsService.create(keyword, accountId, userId, null);
        FilterWordsCreateRspVO filterWordsCreateRspVO = new FilterWordsCreateRspVO();
        BeanUtils.copyProperties(filterWordsEntity, filterWordsCreateRspVO);
        return filterWordsCreateRspVO;
    }


    @Override
    public Boolean update(FilterWordsUpdateReqVO req) {
        Token token = TokenThreadLocal.getToken();
        Integer userId = token.getAccountId();
        return filterWordsService.update(req.getId(), req.getKeyword(), null, 0, userId);
    }

    @Override
    public Integer delete(String ids) {
        return filterWordsService.delete(ids);
    }

    @Override
    public FilterWordsImportRspVO importFile(MultipartFile file, Integer userId) {
        return filterWordsService.importFile(null, file, 0, userId);
    }
}
